package com.bjpowernode.crm.commons.domain;

import com.bjpowernode.crm.commons.contants.Constants;
import org.apache.poi.ss.formula.functions.T;

/**
 * 郭俊才
 * 2021/8/15
 * 统一项目中所有ajax请求的返回值类型，包含返回数据，返回结果，返回信息
 */
public class ResultEntity {


    private Object data;//返回的数据
    private String successCode;//操作结果
    private String message;//操作信息

    public ResultEntity() {
    }

    public ResultEntity(String successCode, String message, Object data) {
        this.data = data;
        this.successCode = successCode;
        this.message = message;
    }

    /**
     * 操作成功没有携带数据
     * @return
     */
    public static  ResultEntity successWithoutData(){

        return new ResultEntity(Constants.SUCCESS_CODE,Constants.NO_MESSAGE,null);
    }

    /**
     * 操作成功,携带数据
     * @param data
     * @return
     */
    public static  ResultEntity successWithData(Object data){

        return new ResultEntity(Constants.SUCCESS_CODE,Constants.NO_MESSAGE,data);
    }

    /**
     * 操作失败，没有数据
     * @param message 传入操作失败的信息
     * @return
     */
    public static ResultEntity failed(String message){

        return new ResultEntity(Constants.FAILED_CODE,message,null);
    }

    @Override
    public String toString() {
        return "ResultEntity{" +
                "data=" + data +
                ", successCode='" + successCode + '\'' +
                ", message='" + message + '\'' +
                '}';
    }


    public Object getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getSuccessCode() {
        return successCode;
    }

    public void setSuccessCode(String successCode) {
        this.successCode = successCode;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
